package cn.tedu.charging.cost.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

/**
 * Redis 配置类
 */
@Configuration
public class RedisConfiguration {

    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory){
        RedisTemplate template = new RedisTemplate();
        //设置key的序列化器 把所有的通过 RedisTemplate 操作(序列化和反序列化)的key都转换成字符串
        template.setKeySerializer(RedisSerializer.string());
        //设置value的序列化器 把所有的通过 RedisTemplate 操作(序列化和反序列化)的value都转换成json
        template.setValueSerializer(RedisSerializer.json());
        template.setConnectionFactory(redisConnectionFactory);
        return template;
    }
}
